/**
 *******************************************************************************
 * @FileName  : usb_def.h
 * @Author    : GaoQiu
 * @CreateDate: 2021-5-15
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */

#ifndef USB_DEF_H_
#define USB_DEF_H_

/* USB PID(packet id) Group. */
#define USB_PID_TYPE_SPECIAL     0x00
#define USB_PID_TYPE_TOKEN       0x01
#define USB_PID_TYPE_HANDSHAKE   0x02
#define USB_PID_TYPE_DATA        0x03

#define USB_PID_TYPE(pid)        ((pid) & 0x03)

//Token
#define USB_PID_OUT
#define USB_PID_IN
#define USB_PID_SETUP
#define USB_PID_SOF

//Data
#define USB_PID_DATA0
#define USB_PID_DATA1
#define USB_PID_DATA2
#define USB_PID_MDATA

//Handshake
#define USB_PID_ACK
#define USB_PID_NACK
#define USB_PID_STALL
#define USB_PID_NYET

//Special
#define USB_PID_PING


/*! Vendor ID */
#define USB_VENDOR_ID_TELINK              (0x248A)//9354


/*! USB Standard Descriptor type define. */
#define USB_DEVICE_DESC_TYPE              0x01
#define USB_CONFIG_DESC_TYPE              0x02
#define USB_STRING_DESC_TYPE              0x03
#define USB_INTERFACE_DESC_TYPE           0x04
#define USB_EDP_DESC_TYPE                 0x05
#define USB_DEV_QUALIFIER_DESC_TYPE       0x06
#define USB_OTHER_SPEED_CONFIG_DESC_TYPE  0x07
#define USB_INTERFACE_POWER_DESC_TYPE     0x08
#define USB_CS_INTERFACE_DESC_TYPE        0x24 /* Class-sepcific interface descriptor. */
#define USB_CS_ENDPOINT_DESC_TYPE         0x25 /* Class-sepcific edndpoint descriptor. */


/*! USB Standard Request define. */
#define USB_GET_STATUS_REQ     0
#define USB_CLEAR_FEAT_REQ     1
#define USB_RFU1               2
#define USB_SET_FEAT_REQ       3
#define USB_RFU2               4
#define USB_SET_ADDR_REQ       5
#define USB_GET_DESC_REQ       6
#define USB_SET_DESC_REQ       7
#define USB_GET_CONFIG_REQ     8
#define USB_SET_CONFIG_REQ     9
#define USB_GET_INTERFACE      10
#define USB_SET_INTERFACE      11
#define USB_SYNC_FRAME_REQ     12
#define USB_MAX_STD_REQ_ID     USB_SYNC_FRAME_REQ

//CDC device request
#define USB_SET_LINE_CODING    0x20
#define USB_GET_LINE_CODING    0x21
#define USB_SET_CTRL_LINE_STA  0x22

/*! USB Request type bitmap define. */
#define USB_DATA_DIR_HOST_TO_DEV   0
#define USB_DATA_DIR_DEV_TO_HOST   1

#define USB_REQ_TYE_STD            0
#define USB_REQ_TYPE_CLASS         1
#define USB_REQ_TYPE_VENDOR        2

#define USB_RECIPIENT_DEV          0
#define USB_RECIPIENT_INTF         1
#define USB_RECIPIENT_EDP          2


/*! USB descriptor length. */
#define USB_LEN_DEVICE_DESC     18
#define USB_LEN_CONFIG_DESC     9
#define USB_LEN_INTF_DESC       9
#define USB_LEN_EDP_DESC        7


/*! USB Language ID. */
#define USB_LANG_ID_CN        0x1404
#define USB_LANG_ID_EN        0x0409

/*! USB request length define. */
#define USB_LEN_STD_REQ        8


/*!< USB data direction. */
#define USB_DATA_DIR_IN        0x80
#define USB_DATA_DIR_OUT       0x00


#endif /* USE_DEF_H_ */
